Cargamos los datos de los índices accionarios:
Datos=read.xlsx("https://www.dropbox.com/s/zltdbdkgvd1nw0g/datos.xlsx?raw=1")
Datos$Fecha=as.Date(Datos$Fecha,
origin = "1899-12-30",
format="%Y-%m-%d")
fig1=ggplot()+
geom_line(aes(x=Fecha, y=DowJones), colour="blue", data=Datos)+
geom_line(aes(x=Fecha, y=IPCcomp), colour="orange", data=Datos)+
geom_line(aes(x=Fecha, y=IPC_Large_Cap), colour="grey", data=Datos)+
geom_line(aes(x=Fecha, y=IPC_Mid_Cap), colour="green", data=Datos)+
geom_line(aes(x=Fecha, y=IPC_Small_Cap), colour="black", data=Datos)+
geom_line(aes(x=Fecha, y=SP500), colour="red", data=Datos)+
xlab("Tiempo")+ylab("Índice base 100")
ggplotly(fig1)
Se corren las prubas de raíz unitaria Dickey Fuller:
DF.DowJones=adf.test(Datos$DowJones,k=0)
DF.IPCcomp=adf.test(Datos$IPCcomp,k=0)
DF.IPC_Large_Cap=adf.test(Datos$IPC_Large_Cap,k=0)
DF.IPC_Mid_Cap=adf.test(Datos$IPC_Mid_Cap,k=0)
DF.IPC_Small_Cap=adf.test(Datos$IPC_Small_Cap,k=0)
DF.SP500=adf.test(Datos$SP500,k=0)
DF.DowJones$p.value
## [1] 0.8256363
DF.IPCcomp$p.value
## [1] 0.342435
DF.IPC_Large_Cap$p.value
## [1] 0.4364869
DF.IPC_Mid_Cap$p.value
## [1] 0.6889994
DF.IPC_Small_Cap$p.value
## [1] 0.8039597
DF.SP500$p.value
## [1] 0.9256399
Ahora se corren las pruebas Dickey-Fuller aumentada a 1 rezago \(k=1\):
DFA.DowJones=adf.test(Datos$DowJones,k=1)
DFA.IPCcomp=adf.test(Datos$IPCcomp,k=1)
DFA.IPC_Large_Cap=adf.test(Datos$IPC_Large_Cap,k=1)
DFA.IPC_Mid_Cap=adf.test(Datos$IPC_Mid_Cap,k=1)
DFA.IPC_Small_Cap=adf.test(Datos$IPC_Small_Cap,k=1)
DFA.SP500=adf.test(Datos$SP500,k=1)
DFA.DowJones$p.value
## [1] 0.8194367
DFA.IPCcomp$p.value
## [1] 0.4095925
DFA.IPC_Large_Cap$p.value
## [1] 0.3937304
DFA.IPC_Mid_Cap$p.value
## [1] 0.4492167
DFA.IPC_Small_Cap$p.value
## [1] 0.6742209
DFA.SP500$p.value
## [1] 0.9167549
De forma siguiente se presenta la prueba Phillips-Perron:
PP.DowJones=pp.test(Datos$DowJones)
PP.IPCcomp=pp.test(Datos$IPCcomp)
PP.IPC_Large_Cap=pp.test(Datos$IPC_Large_Cap)
PP.IPC_Mid_Cap=pp.test(Datos$IPC_Mid_Cap)
PP.IPC_Small_Cap=pp.test(Datos$IPC_Small_Cap)
PP.SP500=pp.test(Datos$SP500)
PP.DowJones$p.value
## [1] 0.8439906
PP.IPCcomp$p.value
## [1] 0.2814121
PP.IPC_Large_Cap$p.value
## [1] 0.3455662
PP.IPC_Mid_Cap$p.value
## [1] 0.4546711
PP.IPC_Small_Cap$p.value
## [1] 0.7028768
PP.SP500$p.value
## [1] 0.9193442
Por último se corre la prueba KPSS, con la cual si de da un P. Value pequeño, significará que la series de tiempo NO serán estacionarias.
KPSS.DowJones=kpss.test(Datos$DowJones)
## Warning in kpss.test(Datos$DowJones): p-value smaller than printed p-value
KPSS.IPCcomp=kpss.test(Datos$IPCcomp)
## Warning in kpss.test(Datos$IPCcomp): p-value smaller than printed p-value
KPSS.IPC_Large_Cap=kpss.test(Datos$IPC_Large_Cap)
## Warning in kpss.test(Datos$IPC_Large_Cap): p-value smaller than printed p-
## value
KPSS.IPC_Mid_Cap=kpss.test(Datos$IPC_Mid_Cap)
## Warning in kpss.test(Datos$IPC_Mid_Cap): p-value smaller than printed p-
## value
KPSS.IPC_Small_Cap=kpss.test(Datos$IPC_Small_Cap)
## Warning in kpss.test(Datos$IPC_Small_Cap): p-value smaller than printed p-
## value
KPSS.SP500=kpss.test(Datos$SP500)
## Warning in kpss.test(Datos$SP500): p-value smaller than printed p-value
KPSS.DowJones$p.value
## [1] 0.01
KPSS.IPCcomp$p.value
## [1] 0.01
KPSS.IPC_Large_Cap$p.value
## [1] 0.01
KPSS.IPC_Mid_Cap$p.value
## [1] 0.01
KPSS.IPC_Small_Cap$p.value
## [1] 0.01
KPSS.SP500$p.value
## [1] 0.01
Hagamos un resumen de pruebas unitaria:
tabla.runit=data.frame("Dickey-fuller"=c(DF.DowJones$p.value,DF.IPCcomp$p.value,DF.IPC_Large_Cap$p.value,DF.IPC_Mid_Cap$p.value,DF.IPC_Small_Cap$p.value,DF.SP500$p.value),
"Dickey-fullerA"=c(DFA.DowJones$p.value,DFA.IPCcomp$p.value,DFA.IPC_Large_Cap$p.value,DFA.IPC_Mid_Cap$p.value,DFA.IPC_Small_Cap$p.value,DFA.SP500$p.value),
"Phillips-Perron"=c(PP.DowJones$p.value,PP.IPCcomp$p.value,PP.IPC_Large_Cap$p.value,PP.IPC_Mid_Cap$p.value,PP.IPC_Small_Cap$p.value,PP.SP500$p.value),
"KPSS"=c(KPSS.DowJones$p.value,KPSS.IPCcomp$p.value,KPSS.IPC_Large_Cap$p.value,KPSS.IPC_Mid_Cap$p.value,KPSS.IPC_Small_Cap$p.value,KPSS.SP500$p.value),
row.names =c("DowJones","IPCcomp","IPC_Large_Cap",
"IPC_Mid_Cap","IPC_Small_Cap","SP500"))
stargazer(tabla.runit,summary=FALSE,type = "html")
##
## <table style="text-align:center"><tr><td colspan="5" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left"></td><td>Dickey.fuller</td><td>Dickey.fullerA</td><td>Phillips.Perron</td><td>KPSS</td></tr>
## <tr><td colspan="5" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">DowJones</td><td>0.826</td><td>0.819</td><td>0.844</td><td>0.010</td></tr>
## <tr><td style="text-align:left">IPCcomp</td><td>0.342</td><td>0.410</td><td>0.281</td><td>0.010</td></tr>
## <tr><td style="text-align:left">IPC_Large_Cap</td><td>0.436</td><td>0.394</td><td>0.346</td><td>0.010</td></tr>
## <tr><td style="text-align:left">IPC_Mid_Cap</td><td>0.689</td><td>0.449</td><td>0.455</td><td>0.010</td></tr>
## <tr><td style="text-align:left">IPC_Small_Cap</td><td>0.804</td><td>0.674</td><td>0.703</td><td>0.010</td></tr>
## <tr><td style="text-align:left">SP500</td><td>0.926</td><td>0.917</td><td>0.919</td><td>0.010</td></tr>
## <tr><td colspan="5" style="border-bottom: 1px solid black"></td></tr></table>
Ya que se demostró que las series de tiempo que interesan son no estacionarias ahora se debe verificar que las mismas tengan una relación de largo plazo. Es decir que, estén "cointegradas". Para esto se calcula la siguiente regresión auxiliar:
\[IPCcomp_t=\alpha+\beta\cdot DowJones_t+\beta\cdot IPC_Large_Cap_t+\beta\cdot IPC_Mid_Cap_t+\beta\cdot IPC_Small_Cap_t+\beta\cdot SP500_t*\varepsilon_t\]
A esta regresión auxiliar le extraemos los residuales y a éstos les aplicamos las pruebas de raíz unitaria. Si los residuales son estacionarios, las series de tiempo están cointegradas, si no, no se tiene la relación de largo plazo que se busca.
eqresid="IPCcomp~DowJones+IPC_Large_Cap+IPC_Mid_Cap+IPC_Small_Cap+SP500"
regresid=lm(eqresid,data=Datos)
residuales=regresid$residuals
tabla.coint1=data.frame(DF=adf.test(residuales,k=0)$p.value,
DFA=adf.test(residuales,k=1)$p.value,
pp=pp.test(residuales)$p.value,
KPSS=kpss.test(residuales)$p.value,
row.names = c("residuales"))
## Warning in adf.test(residuales, k = 0): p-value smaller than printed p-
## value
## Warning in adf.test(residuales, k = 1): p-value smaller than printed p-
## value
## Warning in pp.test(residuales): p-value smaller than printed p-value
## Warning in kpss.test(residuales): p-value greater than printed p-value
stargazer(tabla.coint1,summary = FALSE,type="html")
##
## <table style="text-align:center"><tr><td colspan="5" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left"></td><td>DF</td><td>DFA</td><td>pp</td><td>KPSS</td></tr>
## <tr><td colspan="5" style="border-bottom: 1px solid black"></td></tr><tr><td style="text-align:left">residuales</td><td>0.010</td><td>0.010</td><td>0.010</td><td>0.100</td></tr>
## <tr><td colspan="5" style="border-bottom: 1px solid black"></td></tr></table>
Por lo que se puede apreciar con la prueba de cointegración de Engel y Granger, la serie de tiempo de los residuales es ** estacionaria, por lo tanto estan cointegradas** las series de tiempo que interesan, es decir, se mueven en el mismo sentido, y tienen relación de largo plazo.
Ahora verifiquemos ésto con a prueba de Johansen para integración.
# Dado que el comando de la prueba de Cointegración de johansen utiliza objetos tipo series de tiempo, se convierten las columnas que interesan en los datos a objetos ts.
TS=ts(cbind(Datos$DowJones,Datos$IPCcomp,Datos$IPC_Large_Cap,Datos$IPC_Mid_Cap,Datos$IPC_Small_Cap,Datos$SP500))
cointtest1=ca.jo(TS,type="eigen")
summary(cointtest1)
##
## ######################
## # Johansen-Procedure #
## ######################
##
## Test type: maximal eigenvalue statistic (lambda max) , with linear trend
##
## Eigenvalues (lambda):
## [1] 0.352474631 0.240086910 0.115157673 0.063234454 0.044388289 0.003610552
##
## Values of teststatistic and critical values of test:
##
## test 10pct 5pct 1pct
## r <= 5 | 0.47 6.50 8.18 11.65
## r <= 4 | 5.90 12.91 14.90 19.19
## r <= 3 | 8.49 18.90 21.07 25.75
## r <= 2 | 15.90 24.78 27.14 32.14
## r <= 1 | 35.69 30.84 33.32 38.78
## r = 0 | 56.50 36.25 39.43 44.59
##
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
##
## Series.1.l2 Series.2.l2 Series.3.l2 Series.4.l2 Series.5.l2
## Series.1.l2 1.00000000 1.000000000 1.0000000 1.00000000 1.00000000
## Series.2.l2 27.85268224 -0.001857595 0.3521054 0.02591994 0.16038336
## Series.3.l2 -21.87576623 -0.055483775 -0.7556638 0.01077158 -0.47979233
## Series.4.l2 -6.12977213 -0.131869269 0.4862964 0.09436217 0.46820806
## Series.5.l2 0.02006241 0.105809541 0.6248443 -0.19616668 -0.00215477
## Series.6.l2 -0.38278794 -0.838050774 -2.1186607 -0.53445331 -0.99566309
## Series.6.l2
## Series.1.l2 1.00000000
## Series.2.l2 0.06545840
## Series.3.l2 -0.07259131
## Series.4.l2 0.03099238
## Series.5.l2 0.06472716
## Series.6.l2 -1.33621433
##
## Weights W:
## (This is the loading matrix)
##
## Series.1.l2 Series.2.l2 Series.3.l2 Series.4.l2 Series.5.l2
## Series.1.d -0.005608403 -0.3933163 0.02265711 -0.17647479 -0.018144432
## Series.2.d -0.038559193 -0.3596951 -0.10594331 -0.36064451 -0.006903979
## Series.3.d -0.001763105 -0.3969658 -0.10106180 -0.38678969 0.009670339
## Series.4.d -0.003050460 -0.2114213 -0.07828956 -0.26328582 -0.097083286
## Series.5.d -0.010391507 -0.6505270 -0.04164304 -0.02615745 -0.094993734
## Series.6.d -0.006149963 -0.2247782 0.02541515 -0.17771820 -0.024150547
## Series.6.l2
## Series.1.d 0.01526198
## Series.2.d 0.04671997
## Series.3.d 0.05531048
## Series.4.d 0.02296547
## Series.5.d 0.05213217
## Series.6.d 0.01868488
Como conlusión al ejercicio en el que se incluyen los demás índices accionarios, y después de haber corrido las pruebas de raíz unitaria, así como de cointegración, se llega a la conclusión de que existe la misma entre todos los índices accionarios probados.